function model = ensemble_train_wrap(coverMat, stegoMat, d_sub, L, mode, verbose)
%ENSEMBLE_TRAIN_WRAP call ensemble_train to train ensemble classifier.
%  Usage: model = ensemble_train_wrap(coverMat, stegoMat, d_sub, L, mode)
%    This function preprocess data and then call ensemble_train to train
%    ensemble classifier. It sets the following value in the "settings"
%    value passed to ensemble_train
%      seed_trntst : a random value
%      cover   : 'tmp_cover.mat' (F: coverMat, names: auto generated)
%      stego   : 'tmp_stego.mat' (F: stegoMat, names: auto generated)
%      d_sub   : d_sub from input
%      L       : L from input
%      verbose : verbose
%
%  Input:
%    COVERMAT : M*N matrix for training data (class 0).
%    STEGOMAT : L*N matrix for training data (class 1).
%    D_SUB    : a positive integer.
%    L        : a positive integer.
%    MODE     : one of the following value
%       'same'           -> use same names for all data.
%       'unique'         -> use unique names for all data.
%                          (every line in coverMat matches stegoMat)
%       'auto' (default) -> 'unique' when size match, 'same' otherwise.
%    VERBOSE  : 0 (default) -> supress output
%               1  -> display debug messages.
%
%  Output:
%    Model    : output of ensemble_train, the final ensemble classfier
%               (a set of base learners).
%
if nargin < 5
    mode = 'auto';
end
if strcmpi(mode, 'auto')
    if isequal(size(coverMat), size(stegoMat))
        mode = 'unique';
    else
        mode = 'same';
    end
end

if nargin < 6
    verbose = 0;
end

while 1
    tn = tempname;
    tmp_cover = [tn, '_c.mat'];
    tmp_stego = [tn, '_s.mat'];
    if ~exist(tmp_cover) && ~exist(tmp_stego)
        break;
    end
end

createTmpMat(coverMat, tmp_cover, mode);
createTmpMat(stegoMat, tmp_stego, mode);
settings = struct('cover', tmp_cover, 'stego', tmp_stego, ...
    'seed_trntst', randi(100000), 'd_sub', d_sub, 'L', L, ...
    'verbose', verbose);

if verbose > 0
    disp(settings);
end

model = ensemble_train(settings);
delete(tmp_cover)
delete(tmp_stego)
end